<%-- 
/*
Assignment 1
Class ID        : SE0691
Group           : 1
Due Date        : 20 November 2012
I declare that this assignment is my own work
in accordance with FPT Policy.
*/
--%>

<%@page import="edu.fpt.dal.ServicesDAL"%>
<%@page import="edu.fpt.hib.Services"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="edu.fpt.hib.Apartment"%>
<%@page import="edu.fpt.dal.ApartmentDAL"%>
<%@page import="edu.fpt.hib.Users"%>
<%@page import="edu.fpt.dal.UsersDAL"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Costs and Bill</title>
        <style type="text/css"> <!--@import url("../style.css");--></style>
        <script>function goBack()  {  window.history.back()  }</script>
    </head>
    <body>
        <%@include file="template/header.jsp" %>

        <div id="page">
            <div class="post">
                <h3 class="title">Your payments information is displayed below:</h3>
                <%
                    Users users = UsersDAL.getUsersHQL(session.getAttribute("currentUser").toString());
                    Apartment apart = ApartmentDAL.getApartmentByUserHQL(session.getAttribute("currentUser").toString());
                    StringTokenizer stToken = new StringTokenizer(apart.getUsingServices(), " ");
                    ArrayList<String> ser = new ArrayList<String>();
                    while (stToken.hasMoreElements()) {
                        ser.add(stToken.nextToken().toString());
                    }
                %>
                <h4 class="title">Your payments status is:<% if (apart.getBillStatus()) {%> 
                    <font color="green">Paid</font>
                    <br>Last bill information:
                    <%} else {%>
                    <font color="red">Not Paid</font>
                    <br>This month bill information:
                    <%}
                    %></h4>
                <h4 class="title">Services Fee and Renting fee(if has)</h4>
                <table>
                    <% if (apart.getIsOwn()) {%>
                    <%} else {%>
                    <tr>
                        <td>Renting cost</td>
                        <td><font color="green">3,000,000.0</font></td>
                    </tr>  
                    <%}
                    %>
                    <% for (int i = 0; i < ser.size(); i++) {
                            Services services = ServicesDAL.getByServicesID(ser.get(i));
                            if(services!=null){
                            if (services.getServiceId().equals("KCC001")) {%>
                    <tr>
                        <td><%=services.getServiceName()%></td>
                        <td><font color="green"><%=services.getServicePrice() * apart.getElectricNum()%></font></td>
                    </tr>
                    <%} else if (services.getServiceId().equals("KCC002")) {%>
                    <tr>
                        <td><%=services.getServiceName()%></td>
                        <td><font color="green"><%=services.getServicePrice() * apart.getWaterNum()%></font></td>
                    </tr>
                    <% } else {%>
                    <tr>
                        <td><%=services.getServiceName()%></td>
                        <td><font color="green"><%=services.getServicePrice()%></font></td>
                    </tr>
                    <% }}
                    %>

                    <%}%></table>

                <h4 class="title">Total is: <font color="green"><%=apart.calculateBill()%></font> </h4>
                <% if (apart.getBillStatus()) {%> <font color="green">Thank you for paying in time!</font>
                            <%} else {%>
                            <font color="red">You have 30 days to pay this bill until all your services are stopped.</font>
                            <%}
                            %>

            </div>
        </div>
        <%@include file="template/footer.jsp" %>
    </body>
</html>
